﻿using System;
using System.Data;

public partial class manager_temt_TmpRule : System.Web.UI.Page
{
    DBHelper db = new DBHelper();
    public int tid;
    public string ttitle;
    protected void Page_Load(object sender, EventArgs e)
    {
        tid = Convert.ToInt32(Request.QueryString["id"]);
        RelId.Value = tid.ToString();
        ttitle = (Request.QueryString["title"]);
        if (!IsPostBack)
        {
            bindData();
        }
    }
    private void bindData()
    {
        DataTable dt = db.getList("select * from dict_dept_position_evaluate_detail where relid=" + tid);

        rptDeApply_1.DataSource = dt;
        rptDeApply_1.DataBind();



    }

    protected void btnGet_Click(object sender, EventArgs e)
    {
        string hid = hidBID.Value;
        string sql = "select* from dict_dept_position_evaluate_detail where id=" + hid;
        DataTable dt = db.getList(sql);
        if (dt.Rows.Count > 0)
        {
            DataRow dr = dt.Rows[0];
            txt_mc.Text = dr["mc"].ToString();
            txt_zblh.Text = dr["zblh"].ToString(); ;
            txt_qz.Text = dr["qz"].ToString(); ;
            txt_khbz.Text = dr["khbz"].ToString(); ;
            txt_sjly.Text = dr["sjly"].ToString(); ;

            txt_khpl.Text = dr["khpl"].ToString(); ;
            string isusstr = "0";
            if (dr["isUsing"].ToString() == "True")
            {
                isusstr = "1";
            }
            ddlIsUsing.SelectedValue = isusstr;
        }
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string hid = hidBID.Value;
        string relid = RelId.Value;
        string isUsing = "";
        string mc = txt_mc.Text;
        string zblh = txt_zblh.Text;
        string qz = txt_qz.Text;
        string khbz = txt_khbz.Text;
        string sjly = txt_sjly.Text;

        string khpl = txt_khpl.Text;


        isUsing = ddlIsUsing.SelectedValue;

        string sql = "";
        if (hid == "")
        {

            if (mc != "" && isUsing != "")
            {
                sql = "insert into dict_dept_position_evaluate_detail(mc,zblh,qz,khbz,sjly,khbm,khpl,IsUsing,relid)values('" + mc + "','" + zblh + "','" + qz + "',N'" + khbz + "',N'" + sjly + "',N'',N'" + khpl + "','" + isUsing + "','" + relid + "')";
            }
            else
            {
                Response.Write(CommonHelper.alertMsg("请完善所有信息")); return;
            }
        }
        else
        {
            if (mc != "" && isUsing != "")
            {
                sql = "update dict_dept_position_evaluate_detail set mc='" + mc + "',[zblh]='" + zblh + "',qz='" + qz + "',khbz=N'" + khbz + "',sjly=N'" + sjly + "',khpl=N'" + khpl + "',isUsing='" + isUsing + "' where id=" + hid;
            }
            else
            {
                Response.Write(CommonHelper.alertMsg("请完善所有信息")); return;
            }
        }

        int i = db.executeNoneQuery(sql);
        if (i > 0)
        {
            CacheHelper.clearAllCache();
            Response.Write(CommonHelper.alertMsgAndRedirect("保存成功", Request.Url.LocalPath + Request.Url.Query));
        }
        else
        {
            Response.Write(CommonHelper.alertMsg("保存失败"));
        }
    }
}